/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package database;

/**
 *
 * @author Alejandro
 */
public class DatabaseText extends DatabaseObject {
    public static final String LENGTH = "length";
    private int length = 256;

    public DatabaseText() {
        value = "";
    }

    @Override
    public boolean isValid() {
        if (value == null)
            return false;
        else {
            String s = (String) value;
            return (s.length() <= length);
        }
    }

    @Override
    public void setValue(Object value) {
        try {
            this.value = (String) value;
        } catch (ClassCastException cce) {
            value = null;
        }
    }

    @Override
    public void setParam(String param, Object value) {
        if (param.equals(LENGTH)) {
            length = Integer.parseInt((String) value);
        }
    }

    @Override
    public Object getParam(String param) {
        if (param.equals(LENGTH)) {
            return (Object) length;
        }
        return null;
    }

    @Override
    public String toString() {
        return value.toString();
    }

}
